﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using JM.JCY.BusinessEntity;
using JM.JCY.Proxy;

namespace JM.JCY.SharePointComponent.Department.DepartmentMember
{
    public partial class DepartmentMemberUserControl : UserControl
    {
        public int _deptId { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["DeptId"] != null)
                {
                    using (UserManagementProxy proxy = new UserManagementProxy())
                    {
                        _deptId = Int32.Parse(Request.QueryString["DeptId"].ToString());
                        var dt = proxy.GetDeptById(_deptId, string.Empty);
                        this.lblDeptNameMember.Text = dt[0].DeptName;
                        var memberDT = proxy.GetDepartmentMember(_deptId);
                        this.dlUserMember.DataSource = memberDT;
                        this.dlUserMember.DataBind();
                        //this.gvUserMember.DataSource = memberDT;
                        //this.gvUserMember.DataBind();
                    }

                }
            }
        }

        //protected void gvUserMember_DataBound(object sender, GridViewRowEventArgs e)
        //{
        //    DataRowView drv = (DataRowView)e.Row.DataItem;
        //    if (e.Row.RowType == DataControlRowType.DataRow)
        //    {
        //        Literal viewLink = (Literal)e.Row.Cells[0].FindControl("ltImgPic");
        //        viewLink.Text = "<a href='/PersonalSite/PersonalPages/PublicUser.aspx?StaffId=" + drv["UserId"].ToString() + "'> <img src='" + drv["PhotoImagePath"].ToString() + "' alt='" + drv["UserName"].ToString() + "' height='141px'></a>";

        //    }
        //}

        protected void dlUserMember_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            DataRowView drv = (DataRowView)e.Item.DataItem;
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Literal viewLink = (Literal)e.Item.FindControl("ltImgPic");
                viewLink.Text = "<a href='/PersonalSite/PersonalPages/PublicUser.aspx?StaffId=" + drv["UserId"].ToString() + "'> <img src='" + drv["PhotoImagePath"].ToString() + "' alt='" + drv["UserName"].ToString() + "' width='110px' height='128'></a>";
            }
        }

    }
}
